using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Entities;
using BUS;
using Utility;
public partial class Admin_DanhSachNhanVien : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadData();
        }
    }

    #region"Load data"
    private void LoadData()
    {
        pager.PageSize = 5;
        Criteria c = new Criteria();
        if (txt_TenNV.Text != "")
        {
            c.add(Condition.AND, tbNhanVienEntities.tbNhanVienColumn.TenNV, Condition.LIKE,
                txt_TenNV.Text);
        }
        if (txt_DiaChi.Text != "")
        {
            c.add(Condition.AND, tbNhanVienEntities.tbNhanVienColumn.Diachi, Condition.LIKE,
             txt_DiaChi.Text);
        }
        if (txt_DienThoai.Text != "")
        {
            c.add(Condition.AND, tbNhanVienEntities.tbNhanVienColumn.DienThoai, Condition.LIKE,
             txt_DienThoai.Text);
        }


        int total = 0;
       tbNhanVienEntities.tbNhanVienColection nhanvienCollection =
            tbNhanVienBUS.Get(c.Criter, pager.CurrentIndex, pager.PageSize,
            tbNhanVienEntities.tbNhanVienColumn.MaNV.ToString(), OrderDirection.ASC.ToString(), out total);
        Repeater1.DataSource = nhanvienCollection;
        Repeater1.DataBind();

        pager.ItemCount = total;

    }
    #endregion

    protected void btn_Search_Click(object sender, EventArgs e)
    {
        LoadData();
    }
    protected void lbt_Xoa_Click(object sender, EventArgs e)
    {
        for (int i = 0; i < Repeater1.Items.Count; i++)
        {
            CheckBox cb_Xoa = (CheckBox)Repeater1.Items[i].FindControl("cb_Xoa");
            if (cb_Xoa.Checked == true)
            {
                HiddenField hf_id = (HiddenField)Repeater1.Items[i].FindControl("hf_id");
                int id = int.Parse(hf_id.Value);
                tbNhanVienBUS.Delete(id);
            }
        }
        Response.Redirect(Request.RawUrl);
    }
    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem ||
           e.Item.ItemType == ListItemType.Item)
        {
            tbNhanVienEntities nhanVien = (tbNhanVienEntities)e.Item.DataItem;
            HyperLink hpl_Edit = (HyperLink)e.Item.FindControl("hpl_Edit");
            hpl_Edit.NavigateUrl = "~/Admin/CapNhatNhanVien.aspx?id=" + nhanVien.MaNV.ToString();
        }
    }
    protected void pager_Command(object sender, CommandEventArgs e)
    {
        pager.CurrentIndex = int.Parse(e.CommandArgument.ToString());
        LoadData();

    }
    protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
    {

    }
}
